<template>
    <div class="message">
        <div class="message-content">
            <div class="message-content-img">
                <img :src="img" alt="">
            </div>
            <p> {{username}} </p>
            <div class="message-content-integral iconfont">
                &#xe87f;
                <router-link to="/personal/integral">
                    {{integral}} 积分
                </router-link>
            </div>
            <div class="message-content-login" v-if="show">
              <router-link to="/personal/login">注册 / 登陆</router-link>
            </div>
        </div>
    </div>
</template>

<script>
import { garbageMixin } from '../../utils/mixin'
import { getLocalStorage } from '../../utils/localStorage'
export default {
  mixins: [garbageMixin],
  data () {
    return {
      show: true,
      integral: 0,
      img: 'http://img3.imgtn.bdimg.com/it/u=2778838901,1985278700&fm=15&gp=0.jpg',
      username: 'green'
    }
  },
  mounted () {
    let userImg = getLocalStorage('userImg')
    let userName = getLocalStorage('userName')
    let intergral = getLocalStorage('userIntergration')
    if (userImg === null) {
      this.img = 'http://img3.imgtn.bdimg.com/it/u=2778838901,1985278700&fm=15&gp=0.jpg'
    } else if (userImg !== '') {
      this.img = userImg
      this.href = '/'
    } else {
      this.img = 'http://img3.imgtn.bdimg.com/it/u=2778838901,1985278700&fm=15&gp=0.jpg'
    }
    if (userName === null) {
      this.username = 'green'
    } else if (userName !== '') {
      this.username = userName
      this.show = false
      this.integral = intergral
    } else {
      this.username = 'green'
    }
  }
}
</script>

<style lang="scss" scoped>
@import '../../assets/styles/global';
.message {
    width: 100%;
    background: skyblue;
    margin-top: -1px;
    .message-content {
        padding-left: 50px;
        padding-top: 30px;
        padding-bottom: 30px;
        position: relative;
        font-size: 14px;
        color: white;
        .message-content-img {
            display: block;
            width: 72px;
            height: 72px;
            border: 1px solid #ccc;
            border-radius: 50%;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
            }
        }
        p {
            position: absolute;
            left: 138px;
            top: 48px;
        }
        .message-content-integral {
            position: absolute;
            left: 138px;
            top: 68px;
            font-size: 18px;
            color: black;
            a {
                color: black;
                // text-decoration: none;
                font-size: 14px;
            }
        }
        .message-content-login {
          position: absolute;
          top: 12px;
          right: 12px;
          a {
            color: white;
            text-decoration: none;
          }
        }
    }
}
</style>
